package client.tablete.workspace;

import java.io.IOException;

import websocket4j.client.WebSocket;
import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;

public class CommunicationThread extends AsyncTask<String, Void, String>{

	WebSocket ws = null;
	
	CommunicationActivity commA = null;
	
	public CommunicationThread(CommunicationActivity commA){
		this.commA = commA;
	}
	
	//info[0] = IP; info[1] = PORT;
	@Override
	protected String doInBackground(String... info) {
		
			try {
	//			Log.i("connecting...", "pased");
				ws = new WebSocket(info[0], Integer.valueOf(info[1]), "");
				String message = null;
				try {
					ws.sendMessage("GET");
//					ws.sendMessage(commA.getOption());
					message = ws.getMessage();
				} catch (IOException e) {
					e.printStackTrace();
				}
//				commA.setAnswer(message);
				
				return message;
	//			return ws;
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		
	}
	
//	public void onPostExec(){
//		
//	}
	
	public String askData(String tData){
		String message = null;
		try {
			ws.sendMessage(tData);
			message = ws.getMessage();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return message;
	}


	
}
